#include "fxcc/core/graph/common/RenderStates.h"

using namespace fxcc::graph::common;

bool RenderStates::InitTextureMatType()
{
	m_TextureMatDescs.resize((int)TextureMatType::_Texture_Mat_Count);

	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_NONE] = { "_Texture_Mat_NONE" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_DIFFUSE] = { "_Texture_Mat_DIFFUSE" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_SPECULAR] = { "_Texture_Mat_SPECULAR" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_AMBIENT] = { "_Texture_Mat_AMBIENT" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_EMISSIVE] = { "_Texture_Mat_EMISSIVE" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_HEIGHT] = { "_Texture_Mat_HEIGHT" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_NORMALS] = { "_Texture_Mat_NORMALS" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_SHININESS] = { "_Texture_Mat_SHININESS" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_OPACITY] = { "_Texture_Mat_OPACITY" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_DISPLACEMENT] = { "_Texture_Mat_DISPLACEMENT" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_LIGHTMAP] = { "_Texture_Mat_LIGHTMAP" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_REFLECTION] = { "_Texture_Mat_REFLECTION" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_BASE_COLOR] = { "_Texture_Mat_BASE_COLOR" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_NORMAL_CAMERA] = { "_Texture_Mat_NORMAL_CAMERA" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_EMISSION_COLOR] = { "_Texture_Mat_EMISSION_COLOR" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_METALNESS] = { "_Texture_Mat_METALNESS" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_DIFFUSE_ROUGHNESS] = { "_Texture_Mat_DIFFUSE_ROUGHNESS" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_AMBIENT_OCCLUSION] = { "_Texture_Mat_AMBIENT_OCCLUSION" };
	m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_UNKNOWN] = { "_Texture_Mat_UNKNOWN" };
	//m_TextureMatDescs[(int)TextureMatType::_Texture_Mat_Count] = { "_Texture_Mat_Count" };

	return true;
}

bool RenderStates::InitSamplerDesc()
{
	m_SamplerDescs.resize((int)SamplerType::_count_);
	{

		auto type = SamplerType::_sampler_2d_default_;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "2D Default";
		target.m_Type = type;
	}
	{
		auto type = SamplerType::_sampler_2d_nearest;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "2D Nearest";
		target.m_Type = type;
	}
	{
		auto type = SamplerType::_sampler_2d_array_default;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "2DArray Default";
		target.m_Type = type;
	}

	{
		auto type = SamplerType::_sampler_cube_default_;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "Cube Default";
		target.m_Type = type;
	}
	{
		auto type = SamplerType::_sampler_2d_nearest_no_wrap;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "2D nearest no wrap";
		target.m_Type = type;
	}
	{
		auto type = SamplerType::_sampler_2d_nearest_repeat;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "2D nearest repeat";
		target.m_Type = type;
	}
	{
		auto type = SamplerType::_sampler_cube_mipmap_linear_;
		auto& target = m_SamplerDescs[(int)type];
		target.m_Name = "Cube mipmap Linear";
		target.m_Type = type;
	}




	return true;
}

bool RenderStates::Init()
{
	InitTextureMatType();
	InitSamplerDesc();
	InitTexture2DDescTypeDesc();
	InitCubeMapDescs();

	return true;
}

bool fxcc::graph::common::RenderStates::InitCubeMapDescs()
{
	CubeFaceName = {
	   "Right",
	   "Left",
	   "Top",
	   "Bottom",
	   "Front",
	   "Back"
	};

	captureProjection = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 10.0f);


	captureViews =
	{
		glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
		glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
		glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
		glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
		glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
		glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
	};
	return true;
}
bool RenderStates::InitTexture2DDescTypeDesc()
{
	using _Type = fxcc::graph::common::Texture2DDescType;
	m_Texture2DDescTypeDescs.resize((int)_Type::_texture_2d_desc_end_);

	{
		auto value = _Type::_texture_2d_desc_imaga_desc_;
		m_Texture2DDescTypeDescs[(int)value] = {"from image ", value};

	}

	{
		auto value = _Type::_texture_2d_desc_origin_data_;
		m_Texture2DDescTypeDescs[(int)value] = { "origin data", value };

	}

	{
		auto value = _Type::_texture_2d_desc_origin_file_;
		m_Texture2DDescTypeDescs[(int)value] = { "origin data file", value };

	}
	return true;
}

TextureMatTypeDesc fxcc::graph::common::RenderStates::GetTextureMatDesc(const TextureMatType& type)
{
	return m_TextureMatDescs[(int)type];
}
